package com.px.user.mapper;

import com.px.user.entity.AdminOps;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AdminOpsMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into admin_ops (userId,category,role,url,value,remark) values (#{userId},#{category},#{role},#{url},#{value},#{remark})")
    void insert(AdminOps adminOps);

    @Select({"<script>",
            "select * from admin_ops",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='userId != null'>and userId = #{userId}</if>",
            " <if test='category != null'>and category = #{category}</if>",
            " <if test='role != null'>and role = #{role}</if>",
            " <if test='url != null'>and url = #{url}</if>",
            " <if test='value != null'>and value like #{value}</if>",
            " <if test='remark != null'>and remark like #{remark}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            "</where>",
            "order by ${orderField} desc limit #{startIndex},#{limit}",
            "</script>"})
    List<AdminOps> paging(AdminOps adminOps);

    @Select({"<script>",
            "select count(1) from admin_ops",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='userId != null'>and userId = #{userId}</if>",
            " <if test='category != null'>and category = #{category}</if>",
            " <if test='role != null'>and role = #{role}</if>",
            " <if test='url != null'>and url = #{url}</if>",
            " <if test='value != null'>and value like #{value}</if>",
            " <if test='remark != null'>and remark like #{remark}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            "</where>",
            "</script>"})
    Integer pagingCount(AdminOps adminOps);
}
